using System;
using NUnit.Framework;
using OSCSchema;

namespace OSC.Base.Tests
{
    [TestFixture]
    public class ActivityTests
    {
        private ActivityConverter m_Converter;

        [SetUp]
        public void Setup()
        {
            m_Converter = new ActivityConverter();
        }

        [Test]
        public void TestConvertActivity_PublishedDate()
        {
            var date = DateTime.Now;
            var activity = new Activity
                               {
                                   PublishDate = date
                               };
            var result = m_Converter.Convert(activity);
            Assert.AreEqual(date,result.publishDate);
        }

        [Test]
        public void TestConvertActivity_ActivityTypeStatusUpdate()
        {
            var type = ActivityTypes.StatusUpdate;
            var activity = new Activity
            {
                ActivityType = type
            };
            var result = m_Converter.Convert(activity);
            Assert.AreEqual(activityTemplateTypeRestrictionType.StatusUpdate, result.type);
            Assert.IsTrue(result.typeSpecified);
        }

        [Test]
        public void TestConvertActivity_ActivityTypeDocument()
        {
            var type = ActivityTypes.Document;
            var activity = new Activity
            {
                ActivityType = type
            };
            var result = m_Converter.Convert(activity);
            Assert.AreEqual(activityTemplateTypeRestrictionType.Document, result.type);
            Assert.IsTrue(result.typeSpecified);
        }

        [Test]
        public void TestConvertActivity_ActivityTypeOther()
        {
            var type = ActivityTypes.Other;
            var activity = new Activity
            {
                ActivityType = type
            };
            var result = m_Converter.Convert(activity);
            Assert.AreEqual(activityTemplateTypeRestrictionType.Other, result.type);
            Assert.IsTrue(result.typeSpecified);
        }

        [Test]
        public void TestConvertActivity_ActivityTypePhoto()
        {
            var type = ActivityTypes.Photo;
            var activity = new Activity
            {
                ActivityType = type
            };
            var result = m_Converter.Convert(activity);
            Assert.AreEqual(activityTemplateTypeRestrictionType.Photo, result.type);
            Assert.IsTrue(result.typeSpecified);
        }

        [Test]
        public void TestConvertActivity_ActivityTypeDefaultIsOther()
        {
            var activity = new Activity();
            var result = m_Converter.Convert(activity);
            Assert.IsTrue(!result.typeSpecified);
        }

        [Test]
        public void TestConvertActivity_ApplicaitonId()
        {
            var activity = new Activity
                               {
                                   ApplicationId=123
                               };
            var result = m_Converter.Convert(activity);
            Assert.AreEqual(123,result.applicationID);
        }

        [Test]
        public void TestConvertActivity_ObjectId()
        {
            var activity = new Activity
                               {
                                   Id = 123.ToString()
            };
            var result = m_Converter.Convert(activity);
            Assert.AreEqual(123.ToString(), result.objectID);
        }

        [Test]
        public void TestConvertActivity_TestOwner()
        {
            var activity = new Activity
            {
                Owner = new Person { UserId = 321.ToString()}
            };
            var result = m_Converter.Convert(activity);
            Assert.AreEqual(321.ToString(), result.ownerID);
        }

        [Test]
        public void TestConvertActivity_Publisher()
        {
            var id = "123";
            var name = "name";
            var nameHint = "namehint";
            var email = "mel@orbitone.com";
            var profileUrl = "profileurl";
            var activity = new Activity();
            activity.AddDetail(new Publisher(id,name,nameHint,email,profileUrl));
            var result = m_Converter.Convert(activity);
            Assert.AreEqual(id, result.templateVariables[0].id);
            Assert.AreEqual(name, result.templateVariables[0].name);
            Assert.AreEqual(nameHint, result.templateVariables[0].nameHint);
            Assert.AreEqual(email, result.templateVariables[0].emailAddress);
            Assert.AreEqual(profileUrl, result.templateVariables[0].profileUrl);
            Assert.AreEqual(templateTypeRestrictionType.publisherVariable, result.templateVariables[0].type);
        }

        [Test]
        public void TestConvertActivity_Entity()
        {
            var id = "123";
            var name = "name";
            var nameHint = "namehint";
            var email = "mel@orbitone.com";
            var profileUrl = "profileurl";
            var activity = new Activity();
            activity.AddDetail(new Entity(id, name, nameHint, email, profileUrl));
            var result = m_Converter.Convert(activity);
            Assert.AreEqual(id, result.templateVariables[0].id);
            Assert.AreEqual(name, result.templateVariables[0].name);
            Assert.AreEqual(nameHint, result.templateVariables[0].nameHint);
            Assert.AreEqual(email, result.templateVariables[0].emailAddress);
            Assert.AreEqual(profileUrl, result.templateVariables[0].profileUrl);
            Assert.AreEqual(templateTypeRestrictionType.entityVariable, result.templateVariables[0].type);
        }

        [Test]
        public void TestConvertActivity_Picture()
        {
            var name = "name";
            var url = "http://picture.com";
            var target = "http://click";
            var altText = "alt";
            var activity = new Activity();
            activity.AddDetail(new Picture(name, url, target, altText));
            var result = m_Converter.Convert(activity);
            Assert.AreEqual(name, result.templateVariables[0].name);
            Assert.AreEqual(url, result.templateVariables[0].value);
            Assert.AreEqual(target, result.templateVariables[0].href);
            Assert.AreEqual(altText, result.templateVariables[0].altText);
            Assert.AreEqual(templateTypeRestrictionType.pictureVariable, result.templateVariables[0].type);
        }

        public void TestConvertActivity_Text()
        {
            var name = "name";
            var value = "sometext";
            var activity = new Activity();
            activity.AddDetail(new Text(name, value));
            var result = m_Converter.Convert(activity);
            Assert.AreEqual(name, result.templateVariables[0].name);
            Assert.AreEqual(value, result.templateVariables[0].value);
            Assert.AreEqual(templateTypeRestrictionType.textVariable, result.templateVariables[0].type);
        }

        public void TestConvertActivity_Link()
        {
            var name = "name";
            var value = "someurl";
            var text = "text";
            var activity = new Activity();
            activity.AddDetail(new Link(name, value,text));
            var result = m_Converter.Convert(activity);
            Assert.AreEqual(name, result.templateVariables[0].name);
            Assert.AreEqual(value, result.templateVariables[0].value);
            Assert.AreEqual(text, result.templateVariables[0].text);
            Assert.AreEqual(templateTypeRestrictionType.linkVariable, result.templateVariables[0].type);
        }
    }
}